package com.xiaoshuidi.cloud.module.iot.dal.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoshuidi.cloud.module.iot.dal.mapper.TbBrandDoMapper;
import com.xiaoshuidi.cloud.module.iot.dal.model.account.CategorysByBrandVo;
import com.xiaoshuidi.cloud.module.iot.dal.pojo.TbBrandDo;
import net.sf.cglib.beans.BeanCopier;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Feng
 * @date 2023/6/17
 */
@Repository
public class TbBrandRepository extends ServiceImpl<TbBrandDoMapper, TbBrandDo> {

    public List<CategorysByBrandVo> getCategoryByBrand(String brandNo) {
        LambdaQueryWrapper<TbBrandDo> wrapper = Wrappers.lambdaQuery();
        wrapper.select(TbBrandDo::getBrandNo, TbBrandDo::getBrandName, TbBrandDo::getCategoryNo, TbBrandDo::getCategoryName)
                .eq(TbBrandDo::getBrandNo, brandNo).eq(TbBrandDo::getStatus, "1");
        List<TbBrandDo> tbBrandDos = this.list(wrapper);
        List<CategorysByBrandVo> categorysByBrandVos = new ArrayList<>();
        for (TbBrandDo tbBrandDo : tbBrandDos) {
            CategorysByBrandVo categorysByBrandVo = new CategorysByBrandVo();
            BeanCopier.create(TbBrandDo.class, CategorysByBrandVo.class, false).copy(tbBrandDo, categorysByBrandVo, null);
            categorysByBrandVos.add(categorysByBrandVo);
        }
        return categorysByBrandVos;
    }
}
